import uuid
import time
from datetime import datetime

from sqlalchemy import Column, String, DateTime
from sqlalchemy.dialects.postgresql import Any

from config.database import Base


def gen_uuid():
    timestamp = str(int(time.time()))

    return uuid.uuid5(uuid.NAMESPACE_DNS, str(timestamp) + str(uuid.uuid4()))


class LikerModel(Base):
    __tablename__ = 'tb_liker'
    __table_args__ = {
        'schema': 'reviews'
    }

    liker_id = Column(String(32), default=gen_uuid(), primary_key=True, comment='表索引主键')
    user_id = Column(String(32), nullable=False, comment='用户ID')
    reviews_id = Column(String(32), nullable=False, comment='点评ID')
    like_date = Column(DateTime(timezone=True), default=datetime.now(), comment='点击喜爱的时间')

    def __init__(self, **kw: Any):
        super().__init__(**kw)
        self.liker_id = gen_uuid()
